capture log close

set more off
set matsize 10000

use rep_final, clear

	*noncitizens
	keep if cit==0

* Define control variables 

	local demog "age age2 male yreduc i.racegr"	
	local imm "ysm i.bpl " 
	local fe "i.statefip i.year "
		
	local full "`demog' `imm' `fe' "
	
* Use year to measure time treatment for full sample to evaluate marriage outcome.
	
	g post1=(year>=2013 & year<=2016)
	g post2=(year>=2017)
	
	g treatpost1=treatgr*post1
	g treatpost2=treatgr*post2
	
	
	*GGL's definition
	
		* Divorced 
		gen divorced = (marst == 4)

		* Spouse is US Citizen
		gen us_spouse = 0
		replace us_spouse = 1 if citizen_sp == 0 | citizen_sp == 1 | citizen_sp == 2 

	
		*newly married with cit_sp
		g cit_sp_new =0
		replace cit_sp_new=1 if cit_sp==1 & marrinyr==2 & married==1
	
	local a=1
	foreach controlgr of varlist controlgrdaca  {
		foreach depvar of varlist married divorced cit_sp cit_sp_new {
	
			
			display ""
			display "--------------------------------------"
			
			display "Dependent Variable: `depvar' "
			
			
			display "--------------------------------------"
		
			
			
			*treatpost1 and treatpost2 both compare to pre-period
			
			
			reg `depvar' treatpost1 treatpost2 treatgr `full'  if daca==1|`controlgr'==1   [pweight = perwt] , cluster(statefip)
			est sto e`a'	


			sum `depvar' [fweight=perwt] if e(sample) 
			
			
			local a=`a' + 1
			
			}

					
			
		}

		*Make table 
				esttab e1 e2 e3 e4 ///
					using tableA4.csv, se  ///
					title(Full Sample) ///
					b(%9.4f) se(%9.4f) star(* 0.1 ** 0.05 *** 0.01) ///
					nogaps replace	
				
